class Feed::MoneyFetion < Feed
  validates_presence_of :added_money
  validates_presence_of :user_id,
    :money
    
  def before_create
    self.version = 1
    self.added_money = 500
    self.money = user.money + 500
  end
  
  def after_create
    user.money += added_money
    user.save(false)
    # 奖励介绍人
    feed = Feed::MoneyIntroduceToJoin.find_by_introducedor_id(user.id)
    Feed::MoneyIntroduceToBindFetion.create!(
      :user_id => feed.user_id,
      :introducedor_id => user.id,
      :mobile => user.mobile
    ) if feed.present? and Feed::MoneyIntroduceToBindFetion.find_by_mobile(user.mobile).nil?
  end
  
  # to template
  def to_t
    ":user于:created_at_ago_in_words前:link_to_bind_fetion了飞信,获得了:added_money麦粒"
  end
end